layui.define(["plus", "plusConfig", "plusUtil"], function (exports) {
  "use strict";

  var table = layui.table,
    layer = layui.layer,
    plus = layui.plus,
    config = layui.plusConfig,
    plusUtil = layui.plusUtil;

  var fast = {
    //初始化table
    initTable: function (op) {
      var elem = op.elem ? op.elem.replace("#", "") : "datagrid";
      var id = op.id ? op.id.replace("#", "") : elem;
      var defaultToolbar = op.defaultToolbar ? op.defaultToolbar : "";
      var cellmin = op.cellMinWidth ? op.cellMinWidth : 80;
      var limit = op.limit ? op.limit : 20;
      var skin = op.skin ? op.skin : "";
      var size = op.size ? op.size : "md";
      var page = op.page ? op.page : true;
      var totalRow = op.totalRow ? op.totalRow : false;
      var where = op.where ? op.where : {};
      var even = op.even ? op.even : true;
      var done = op.done
        ? op.done
        : function () {
            plus.resizeTableHeight();
          };
      var option = {
        elem: "#" + id,
        defaultToolbar: defaultToolbar,
        url: op.url,
        cols: op.cols,
        data: op.data,
        cellMinWidth: cellmin,
        page: page,
        totalRow: totalRow,
        limits: [15, 20, 40, 60, 80, 100],
        limit: limit,
        loading: false,
        skin: skin,
        even: even,
        size: size,
        where: where,
        parseData: function (res) {
          return {
            code: 0,
            msg: res.msg,
            count: res.count,
            data: res.data,
          };
        },
        done: function (res, curr, count) {
          done();
          plus.resizeTableHeight();
          //如果是异步请求数据方式，res即为你接口返回的信息。
          //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
          console.log(res);
          //得到当前页码
          console.log(curr);

          //得到数据总量
          console.log(count);
        },
        error: function (res, msg) {
          console.log(res, msg);
        },
      };
      op.toolbar ? (option.toolbar = "#"+op.toolbar) : "";
      op.data ? (option.data = op.data) : "";
      var insTb = table.render(option);
      return insTb;
    },
  };

  exports("fast", fast);
});
